29. Solution: Create and Apply Styles
Create and Apply Styles Solution
Styles are meant to add consistency and reduce repetitive attributes in multiple views.
Notes on Solution Code
Styles
After completing this exercise, your final styles.xml file should contain the following styles:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- Used for settings preference theme -->
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
<!-- COMPLETED (1) Create a style that shows a Sunshine logo instead of a title -->
<!-- forecast activity action bar styles -->
<style name="ActionBar.Solid.Sunshine.NoTitle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">@drawable/ic_logo</item>
</style>
<!-- COMPLETED (2) Create a style for MainActivity called AppTheme.Forecast that uses our custom ActionBar style -->
<style name="AppTheme.Forecast" parent="@style/AppTheme">
<item name="actionBarStyle">@style/ActionBar.Solid.Sunshine.NoTitle</item>
</style>
<!-- COMPLETED (3) Create the DetailLabel style -->
<!-- Style used in the DetailActivity for the labels of the extra weather information -->
<style name="DetailLabel" parent="@style/TextAppearance.AppCompat.Title">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/detail_accent_label</item>
<item name="android:fontFamily">sans-serif</item>
</style>
<!-- COMPLETED (4) Create the ExtraWeatherMeasurement style -->
<!-- Style used in the DetailActivity for the values of the extra weather information -->
<style name="ExtraWeatherMeasurement" parent="@style/TextAppearance.AppCompat.Headline">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@android:color/white</item>
</style>
</resources>
And these styles should then be applied to the appropriate views.
Theme
Additionally, to use the AppTheme.Forecast as the MainActivity's new theme, you should include this line of code in the AndroidManifest within the main activity tag:
android:theme="@style/AppTheme.Forecast"
Solution Code
Solution: [S12.02-Solution-Styles][Diff]